{% extends 'shop/base.html' %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <img src="{{ product.image.url }}" class="img-fluid rounded" alt="{{ product.name }}">
    </div>
    <div class="col-md-6">
        <h2>{{ product.name }}</h2>
        <p class="text-muted">商品ID: {{ product.id }}</p>
        <h3 class="my-4">¥{{ product.price }}</h3>
        <p>库存: {{ product.stock }}</p>
        <p>{{ product.description }}</p>
        
        {% if user.is_authenticated %}
        <form action="{% url 'add-to-cart' %}" method="post" class="mt-4">
            {% csrf_token %}
            <input type="hidden" name="product_id" value="{{ product.id }}">
            <div class="input-group mb-3" style="max-width: 200px;">
                <input type="number" name="quantity" class="form-control" value="1" min="1" max="{{ product.stock }}">
                <button type="submit" class="btn btn-primary">加入购物车</button>
            </div>
        </form>
        {% else %}
        <div class="alert alert-info mt-4">
            请<a href="{% url 'login' %}">登录</a>后购买商品
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}